 $(document).ready(function(){
	
	 ajax();

  })

function ajax(){
	 $.ajax({
			type : "GET",
			url : "/partyBuilding/mcol",
			contentType : "application/json",
			dataType : "json",
			success : function(data) {
				//alert(JSON.stringify(data));
				
				if(data.code == "200") {
					var data = data.mCols;
					header(data);
					 footer();
				     showTime();
				     $("#clear").on("click",function(){
				         $("#username").val("");
				         $("#psd").val("");
				     })
				     photo();
				     
				}
			},
			error : function() {
				
			}
		});  
	 
 }
 function scol(node){
	 var pkMcol = node.getAttribute("pkMcol");
	 
	 $.ajax({
			type : "GET",
			url : "/partyBuilding/scol/mcol/"+pkMcol,
			contentType : "application/json",
			dataType : "json",
			success : function(data) {
				//alert(JSON.stringify(data));
				
				if(data.code == "200") {
					$("#"+pkMcol).html("");
					$.each(data.sCol, function(num, sCol) {
					$("#"+pkMcol).append('<li style="background-color: transparent;">'+
							'<a onclick="scolHref(this)" pkScol="'+sCol.pkScol+'" fkMcol="'+sCol.fkMcol+'" style="color: rgb(255, 255, 255); font-size: 13px; border-top-color: white; border-bottom-color: rgb(68, 68, 68); line-height: 20px;" href="#">'+
							sCol.scolName+'</a></li>'
								);
				})
				}
			},
			error : function() {
				
			}
		});  
	 
 }
 function mcol(node){
	 var pkMcol = node.getAttribute("pkMcol");

	 switch (pkMcol)
	  {
	  case "1":
		  window.location.href="../parTre/parTre.html";
		  setCookie("pkMcol",pkMcol);
	    break;
	  case "2":
		  window.location.href="../innoGood/innoGood.html"
	    break;
	  case "3":
		  window.location.href="../onlSch/onlSch.html";
	    break;
	  case "4":
		  window.location.href="../parMem/parMem.html";
	    break;
	  case "5":
		  window.location.href="../parVideo/pVideo.html";
	    break;
	  case "6":
		  window.location.href="../parSys/parSys.html";
	    break;
	  }

 }
 
 function scolHref(node){
	 var pkScol = node.getAttribute("pkScol");
//alert(pkScol);
	 switch (pkScol)
	  {
	  case "1":
		  window.location.href="../parTre/notice.html";
		  setCookie("pkScol",pkScol);
	    break;
	  case "2":
		  window.location.href="../parTre/parNews.html";
		  setCookie("pkScol",pkScol);
	    break;
	  case "4":
		  window.location.href="../innoGood/theLearning.html";
		  setCookie("pkScol",pkScol);
	    break;
	  case "5":
		  window.location.href="../innoGood/actTre.html";
		  setCookie("pkScol",pkScol);
	    break;
	  case "6":
		  window.location.href="../innoGood/chaPro.html";
		  setCookie("pkScol",pkScol);
	    break;
	  case "7":
		  window.location.href="../onlSch/test.html";
		  setCookie("pkScol",pkScol);
	    break;
	  case "8":
		  window.location.href="../onlSch/parFab.html";
		  setCookie("pkScol",pkScol);
	    break;
	  case "9":
		  window.location.href="../onlSch/litWork.html";
		  setCookie("pkScol",pkScol);
	    break;
	  case "10":
		  window.location.href="../onlSch/parCon.html";
		  setCookie("pkScol",pkScol);
	    break;
	  case "11":
		  window.location.href="../parVideo/repVideo.html";
		  setCookie("pkScol",pkScol);
	    break;
	  case "12":
		  window.location.href="../parVideo/hisVideo.html";
		  setCookie("pkScol",pkScol);
	    break;
	  case "13":
		  window.location.href="../parSys/discuss.html";
		  setCookie("pkScol",pkScol);
	    break;
	  
	  }

 }
function header(data){
  
    $('.content').prepend('<header id="header"><div><img style="width:100%" src="../../img/u2.png"></div></header>');
    
    var nav_bar = '<div style="height:25px" id="location">当前位置：首页</div>'+'<div style="height:35px"><nav id="zlight-nav">'+
					'<ul id="zlight-main-nav">'+
						'<li class="zlight-active"><a href="../index/index.html">首页</a></li>'+
						
					'</ul>'+
				'</nav></div>';
    $("#nav-bar").html(nav_bar);
   for(var i =0;i<6;i++){
    $("#zlight-main-nav").append('<li class="zlight-dropdown">'+
							'<a href="#" pkMcol="'+data[i].pkMcol+'" onMouseOver="scol(this)" onclick="mcol(this)">'+data[i].mcolName+'</a>'+
							'<ul class="zlight-submenu" id="'+data[i].pkMcol+'">'+
								/*'<li><a href="#">公告公示</a></li>'+
								'<li><a href="#">党建新闻</a></li>'+*/
							'</ul>'+
						'</li>');
    }
   $("#zlight-main-nav").append('<li class="zlight-dropdown">'+
			'<a href="#">更多</a>'+
			'<ul class="zlight-submenu">'+
				'<li><a href="#">更多1</a></li>'+
				'<li class="zlight-dropdown">'+
					'<a href="#">更多2 </a>'+
					'<ul class="zlight-submenu"style="margin-left:0px">'+
						'<li><a href="#">更多 1</a></li>'+
                        '<li><a href="#">更多 1</a></li>'+
					'</ul>'+
				'</li>'+
			'</ul>'+
		'</li>');
    
    var img_div =  '<div><img style="width:100%" src="../../img/u37.png"></div>';
    $("#img-div").html(img_div);
    
    var left_div = '<div class="time">本地时间：<div id="time_a"></div></div>'+'<div class=a-div><img src="../../img/u59.png">'+
    '<a href="http://cpc.people.com.cn"><img style="width:100%;margin-top:17px;" src="../../img/u43.png"></a><a href="http://www.eastday.com"><img style="width:100%;margin-top:17px;" src="../../img/u45.png"></a><a href="http://www.qstheory.cn"><img style="width:100%;margin-top:17px;" src="../../img/u47.PNG"></a>'+
    '<a href="http://www.cntheory.com"><img style="width:100%;margin-top:17px;" src="../../img/u49.PNG"></a><a href="http://www.hzic.edu.cn"><img style="width:100%;margin-top:17px;" src="../../img/u51.PNG"></a><a href="http://www.studytimes.cn"><img style="width:100%;margin-top:17px;" src="../../img/u41.PNG"></a>'+
    '<a href="http://www.dangjiancn.com"><img style="width:100%;margin-top:17px;" src="../../img/u53.PNG"></a><a href="http://zqb.cyol.com"><img style="width:100%;margin-top:17px;" src="../../img/u55.PNG"></a><a href="http://www.jfdaily.com"><img style="width:100%;margin-top:17px;" src="../../img/u57.PNG"></a>'+
    '<a href="http://www.gmw.cn"><img style="width:100%;margin-top:17px;" src="../../img/u39.png"></a></div>';
    $("#left-div").html(left_div);
    

    var right_div = '<div class="login-div">'+ 
    '<div style="margin-bottom:10px;"><b>管理员登录</b></div>'+
    '<div>帐号：<input id="username" style="width:120px;margin-bottom:10px;" type="text"><br />密码：<input id="psd"style="width:120px;margin-bottom:10px;" type="password"></div>'+
    '<div><input type="button" id="login" value="登录" style="margin-left:45px;"class="am-btn am-btn-primary am-btn-xs"><input type="button" value="清空" id="clear" style="margin-left:15px;" class="am-btn am-btn-primary am-btn-xs"></div></div>'+
    '<div class="member-div" id="slide"><img style="width:100%"src="../../img/u108.png">'+
    '<div class="slide_module" id="miaovSlide"><div class="wrap"><ul id="slide-ul">'+
           
        '</ul></div></div></div>';
    $("#right-div").html(right_div);
    
    
}

function photo(){
	$.ajax({
			type : "GET",
			url : "/partyBuilding/partyMem/random",
			contentType : "application/json",
			dataType : "json",
			success : function(data) {
				//alert(JSON.stringify(data));
				
				if(data.code == "200") {
					$("#slide-ul").html("");
					$.each(data.partyMem, function(num, partyMem) {
		                 $("#slide-ul").append('<li><a href="#" pkPartyMem="'+partyMem.pkPm+'"onclick="info(this)"><img src="'+partyMem.pmPhotoUrl+'" />'+partyMem.pmName+'</a></li>');
		            })
		            $('#zlight-nav').zlightMenu(); 
				     slide();
				     $("#login").on("click",function(){
				    	 login();
				    	
				     })
				}
			},
			error : function() {
				
			}
		});  
}



function login(){
	var admUsername = $("#username").val();
	if (admUsername == "") {
		alertModal("提示", "用户名未填写");
		return false;
	}

	var admPwd = $("#psd").val();
	if (admPwd == "") {
		alertModal("提示", "密码未填写");
		return false;
	}

	var content = {};
	content["admName"] = admUsername;
	content["admPwd"] = admPwd;

	$.ajax({
		type : "POST",
		url : "/partyBuilding/admin/login",
		data : encrypt(content),
		contentType : "application/json",
		dataType : "json",
		success : function(data) {
			//ALERT(JSON.stringify(data));
			if (data.code == "200") {
				setCookie("admUsername",admUsername);
				
				// 跳转进入后台
				window.location.href = "/partyBuilding/back/index/index.html";
			} else {
				alertModal("警告", data.message);
			}
		},
		error : function() {
			alertModal("警告", "服务器开小差了");
		}
});
}
function footer(){
    $('.content').append('<footer class="admin-content-footer" style="margin-top:850px;background:#ffffff">'+
		'<p style="text-align:center;" class="am-padding-left">'+
			'<a href="">关于我们</a>&nbsp;&nbsp;&nbsp;<a href="">网站简介</a>&nbsp;&nbsp;&nbsp;'+
            '<a href="">加为收藏</a>&nbsp;&nbsp;&nbsp;<a href="">版权所有</a>&nbsp;&nbsp;&nbsp;<a href="">管理登录</a><br />'+
		'</p>'+'<p style="margin-top:-0.6em;text-align:center;color:black" class="am-padding-left">'+
			'Copyright © 浙江工商大学计算机与信息工程学院<br />'+
		'</p>'+
'</footer>');

}

/*显示时间*/
function showTime() {
	var now = new Date();
	var year = now.getFullYear();
	var month = now.getMonth()+1;
	var date = now.getDate();
	var day = now.getDay();
	var hour = now.getHours();
	var minutes = now.getMinutes() < 10 ? ("0" + now.getMinutes()) : now.getMinutes();
	var seconds = now.getSeconds() < 10 ? ("0" + now.getSeconds()) : now.getSeconds();
	
	var days = ["日", "一", "二" ,"三", "四", "五", "六"];
	
	nowStr = year + "年" + month + "月" + date + "日" ;
    week = " 星期" + days[day];
    time =  hour + ":" + minutes + ":" + seconds;
	
	$("#time_a").html(nowStr +' '+week+' '+time);
	
	window.setInterval(function(){
		var now = new Date();
		var year = now.getFullYear();
		var month = now.getMonth()+1;
		var date = now.getDate();
		var day = now.getDay();
		var hour = now.getHours();
		var minutes = now.getMinutes() < 10 ? ("0" + now.getMinutes()) : now.getMinutes();
		var seconds = now.getSeconds() < 10 ? ("0" + now.getSeconds()) : now.getSeconds();
		
		var days = ["日", "一", "二" ,"三", "四", "五", "六"];
		
		nowStr = year + "年" + month + "月" + date + "日" ;
        week = " 星期" + days[day];
        time =  hour + ":" + minutes + ":" + seconds;
		
		$("#time_a").html(nowStr +' '+week+' '+time);
	}, 1000); 
	
}

// 轮播图
function slide(){
    var oUl = document.getElementById("slide-ul");
        var speed = -3;
        oUl.innerHTML += oUl.innerHTML;
        var ulHeigth = oUl.offsetHeight;
        setInterval(function () {
            if (oUl.offsetTop < -ulHeigth / 2)
                oUl.style.top = '0px';
            else if (oUl.offsetTop > 0)
                oUl.style.top = -ulHeigth / 2 + 'px';
            oUl.style.top = oUl.offsetTop + speed+'px';
        }, 30);

}

